<template>
	<view style="position: relative;" v-if="invitation">
		<image :src="path+invitation.image" mode="widthFix" style="width: 100%;"></image>
		<view style="width: 100%;position: absolute;top: 0;">
			<view style="width: 100%;height: 300px;"></view>
			<view class="kuang">
				<view style="height: 30px;font-size: 14px;text-align: center;font-weight: 700;">注册账号</view>
				<view style="height: 30px;line-height: 30px;font-size: 14px;">账号</view>
				<input v-model="username" style="width: 94%;height: 40px;border: 1px solid #e5e5e5;padding: 0 3%;border-radius: 15px;"/>
				<view style="height: 30px;line-height: 30px;font-size: 14px;margin-top: 10px;">密码</view>
				<input v-model="password" style="width: 94%;height: 40px;border: 1px solid #e5e5e5;padding: 0 3%;border-radius: 15px;"/>
				<view style="width: 100%;height: 10px;"></view>
			</view>
			<view @click="register()" class="button">立即注册</view>
		</view>
	</view>
</template>

<script>
	import api from '@/static/js/request.js'
	export default {
		data() {
			return {
				path: api.getPath(),
				
				code: '',
				username: '',
				password: '',
				invitation: null,
			}
		},
		onLoad(option) {
			this.code = option.code;
			this.getInvitationByCode();
		},
		methods: {
			getInvitationByCode(){
				let _this = this;
				api.getInvitationByCode({
					code: this.code
				}).then((res)=>{
					_this.invitation = res.data;
				})
			},
			register(){
				let _this = this;
				api.register({
					username: this.username,
					password: this.password,
					code: this.code,
				}).then((res)=>{
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}).finally(()=>{
					_this.downloadFile();
				})
			},
			downloadFile(){
				var href = this.invitation.downloadLink;
				window.open(href, '_blank');
				// uni.downloadFile({
				// 	url: this.invitation.downloadLink, //仅为示例，并非真实的资源
				// 	success: (res) => {
				// 		if (res.statusCode === 200) {
				// 			console.log('下载成功');
				// 		}
				// 	}
				// });
			},
		}
	}
</script>

<style>
	.kuang{
		width: 84%;
		padding: 10px 3%;
		background-color: #FFFFFF;
		margin: 10px auto;
		border-radius: 8px;
	}
	.button{
		width: 90%;
		height: 40px;
		line-height: 40px;
		border-radius: 8px;
		text-align: center;
		color: #FFFFFF;
		font-size: 14px;
		margin: 0 auto;
		background-color: #F05098;
	}
</style>
